<template>
  <el-row class="navheader">
    <el-col :span="18" class="logo" v-if="true == true">
      <el-col :span="1">
        <img
          src="../assets/hui.png"
          alt=""
          @click="$router.push({ path: '/' })"
        />
      </el-col>
      <el-col :span="23">
        <p class="bold">{{AppName}}</p>
      </el-col>
    </el-col>
    <el-col :span="6" class="navRight">
      <div class="title">
        用户：{{ policeName }}
        <span class="el-icon-back icon" @click="$router.go(-1)" v-if="$route.path !== '/tailoring/index' && $route.path !== '/prison/index'
        && $route.path !== '/lackmaterial/index' && $route.path !== '/bagscut/index' && $route.path !=='/receivearea/index'
        && $route.path !=='/tallyarea/index' && $route.path !=='/incomeremind/index' && $route.path !== '/cutinfo/index'"></span>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import { checkUser, getTouchScreenInfo, getBindUserInfo } from '@/api/common'
export default {
  name: 'navheader',
  data () {
    return {
      siteName: '', // 监区的地点名称
      policeName: '',
      text: '',
      AppName: ''
    }
  },
  computed: {
    // ...mapState({
    //   list: state => state.demo.list
    // })
  },
  watch: {
    $route (newVal) {
      let vm = this
      // 判断是否有参数
      if (newVal.fullPath.indexOf('type=') > -1) {
        var types = newVal.fullPath.substr(newVal.fullPath.indexOf('type=') + 5)
        switch (types) {
          case 'M100001' :vm.AppName = '箱包面料'; break
          case 'C100001' :vm.AppName = '箱包裁片'; break
          case 'F100001' :vm.AppName = '箱包辅料'; break
          case 'F100003' :vm.AppName = '电子辅料'; break
          default:vm.AppName = newVal.meta.title; break
        }
      } else {
        vm.AppName = newVal.meta.title
      }
    }
  },
  methods: {
    // 获取用户信息
    getBindUserInfo () {
      let vm = this
      getBindUserInfo().then((response) => {
        if (
            response.data &&
            response.data.length &&
            response.data.length > 0
          ) {
          vm.checkUser(response.data[0])
        }
      })
    },
    // 获取触摸屏信息
    getTouchScreenInfo () {
      let vm = this
      getTouchScreenInfo().then((response) => {
        if (response.data) {
          vm.setLocalStorage(
              'WarehouseFlnkID',
              JSON.stringify(response.data.WarehouseJson)
            )
          vm.setLocalStorage('OrgID', response.data.AssociatedOrgs)
          vm.setLocalStorage(
              'ProductLineFlnkID',
              response.data.ProductLineFlnkID
            )
          vm.setLocalStorage('ShelfFlnkID', response.data.ShelfFlnkID)
          vm.setLocalStorage('ScreenFlnkID', response.data.FlnkID)
          vm.setLocalStorage('OrgNames', response.data.OrgName)
        }
      })
    },
    checkUser (infos) {
      let vm = this
      let params = {
        UserID: infos.UserID,
        UserPwd: infos.Pwd
      }
      checkUser(params).then((response) => {
        if (
            response.data &&
            response.data.length &&
            response.data.length > 0
          ) {
          vm.policeName = response.data[0].ObjectName
          vm.setLocalStorage('UserFlnkID', response.data[0].FlnkID)
          vm.setLocalStorage('UserName', response.data[0].ObjectName)
        }
      })
    }
  },
  mounted () {
    var vm = this
    console.log(this.$store.state)
    // if(vm.isAndroid()){
    //   if(!vm.getLocalStorage('UserFlnkID')){
    //     window.android.recognitionFace()
    //   }
    // }else{
    vm.getBindUserInfo()
    vm.getTouchScreenInfo()
    // }
    vm.AppName = vm.$route.meta.title
  }
}
</script>
<style lang="scss">
@import "../css/navheader.scss";
</style>
